<template>
  <div id="balance_recharge">
    <c-title :hide="false" text="充值"></c-title>
    <img :src="top_img" alt="" style="width: 100%;display: block;" v-if="top_img">
    <!-- 优化 -->
    <diyBackGround></diyBackGround>
    <div class="addressCell" v-if="$route.params.plugin == 'store_oil_station'" @click="getStoreList">
      <div class="addressCell_l flex">
        <i class="iconfont icon-dizhi1"></i>
        <div class="txt" v-if="full_address">{{ full_address }}</div>
      </div>
      <div class="addressCell_r flex">
        <i class="iconfont icon-icon_more11"></i>
      </div>
    </div>
    <div class="main" :style="{'margin-top':$route.params.plugin == 'store_oil_station'?'':'-11rem'}">
      <template v-if="priceDifferencePool">
        <!-- price-difference-pool 插件的充值页 复用样式 -->
        <div class="myBalance f-bold f-15">当前{{ diyname }}：{{ credit2 }}</div>
        <div class="sum f-bold f-24">{{ $i18n.t("money") }}<input type="number" v-model.trim="money" placeholder="请输入金额" /></div>
      </template>
      <template v-if="tagBalance">
        <!-- tag-balance 标签充值 插件 复用样式 -->
        <div class="myBalance f-bold f-15">当前{{diyname}}：{{ credit2 }}</div>
        <div class="sum f-bold f-24">{{ $i18n.t("money") }}<input type="number" v-model.trim="money" placeholder="请输入金额" /></div>
      </template>

      <template v-if="$route.params.plugin == 'store_oil_station'">
        <!-- 石油项目 余额充值 -->
        <div class="myBalance f-bold f-15">我的{{ balanceLang }}（元）：{{ credit2 }}</div>
        <div v-if="diy_amount && diy_amount.length > 0" class="activityItem" style="margin: 0.875rem 0;">
          <!-- 自定义充值金额 -->
          <div class="acitem" :class="{'activeAcitemStyle': diy_money_index == index}" v-for="(item, index) in diy_amount" :key="index" @click.stop="selectDiyNum(index)">
            <div class="flex-column" style="overflow: hidden;">
              <div class="left f-20 f-bold"><small class="f-13">{{ $i18n.t("money") }}</small>{{ item.amount }}</div>
              <div class="left f-11 line-clamp-2" style="color: #999;" v-v-if="item.diy_text">{{item.diy_text}}</div>
            </div>
          </div>
          <div class="acitem" :class="{'activeAcitemStyle': diy_money_index == diy_amount.length}" @click.stop="selectDiyNum(diy_amount.length)">
            <input class="f-16" type="number" v-model.trim="money" placeholder="自定义金额"/>
          </div>
        </div>
        <div class="sum f-24 f-bold">{{ $i18n.t("money") }}<input type="number" v-model.trim="money" placeholder="请输入金额" @input="throttledMoneyChange" /></div>
        <template v-if="activity_new.length > 0">
          <div class="activity_box">
            <div class="txt">充值活动</div>
            <div class="activity_lis" v-for="(item, index) in activity_new" :key="index">
              <div class="activity_time" v-for="(items, ind) in item.desc" :key="ind">{{ items }}</div>
              <div class="activity_item" v-for="(items, ind) in item.value" :key="ind">{{ items }}</div>
            </div>
          </div>
        </template>
      </template>
      <template v-else>
        <div class="myBalance f-bold f-15">我的{{ balanceLang }}（元）：{{ credit2 }}</div>
        <div class="sum f-bold f-24" v-if="diy_amount && diy_amount.length == 0">{{ $i18n.t("money") }}<input type="number" v-model.trim="money" :placeholder="min_recharge?`最低起充金额${min_recharge}元`:'请输入金额'" /></div>

        <div v-if="diy_amount && diy_amount.length > 0" class="activityItem" style="margin: 0.875rem 0;">
          <!-- 自定义充值金额 -->
          <div class="acitem" :class="{'activeAcitemStyle': diy_money_index == index}" v-for="(item, index) in diy_amount" :key="index" @click.stop="selectDiyNum(index)">
            <div class="left f-20 f-bold"><small class="f-13">{{ $i18n.t("money") }}</small>{{ item }}</div>
          </div>
          <div class="acitem" :class="{'activeAcitemStyle': diy_money_index == diy_amount.length}" @click.stop="selectDiyNum(diy_amount.length)">
            <input class="f-16" type="number" v-model.trim="diymoney" placeholder="自定义金额"/>
          </div>
        </div>
        <template v-if="activatDes">
          <div class="activityBox" v-if="activatDes.recharge_activity_start">
            <div class="txt f-bold f-15">充值活动</div>
            <div class="activityTime f-13">活动时间：{{ activatDes.recharge_activity_start }}——{{ activatDes.recharge_activity_end }}</div>
            <div class="activityTime  f-13" v-if="activatDes.recharge_activity_fetter == -1 || activatDes.recharge_activity_fetter == 0">不限</div>
            <div class="activityTime  f-13" v-else>参与次数：每人最多参与{{ activatDes.recharge_activity_fetter }}次</div>
          </div>
          <div class="activityItem" v-if="activatDes && activatDes.sale">
            <div class="acitem" v-for="(item, index) in activatDes.sale" :key="index" @click.stop="selectActivityNum(item.enough)">
              <div class="left f-20 f-bold"><small class="f-13">{{ $i18n.t("money") }}</small>{{ item.enough }}</div>
              <div class="right f-11">赠送{{ discountType(item.give) }}</div>
            </div>
          </div>
        </template>
        <template v-if="this.$route.name == 'YccRecharge'">
          <div class="tips"><span style="color: #666">例如：</span>人民币1元等于{{ recharge_double }}个{{ plugin_name }}</div>
        </template>
      </template>
    </div>
    <div class="cellOther" @click="couponShow" v-if="$route.params.plugin == 'store_oil_station' && member_coupon_list.length > 0">
      <div class="cellOther_l">优惠券</div>
      <div class="cellOther_r">{{ coupon_size_c }}</div>
    </div>
    <div class="cellOther" v-if="$route.params.plugin == 'store_oil_station' && money && recharge_new">
      <div class="cellOther_l">实付金额</div>
      <div class="cellOther_r">¥{{ recharge_new.actual_pay }}</div>
    </div>
    <!-- && display_switch_new && display_switch_new.invoice -->

    <invoicePop ref="invoicePop" :balance_invoice="true" @openAddList="invoiceShowAddressFun" @confirm="subInvoice" :addressData="addressData"></invoicePop>

    <div class="b-r-12 bg-white p-12 m-12" v-if="plugins_new['balance-reward']">
      <!-- balance-reward 余额充值机制 -->
      <div class="f-bold f-15 t-l">{{ plugins_new['balance-reward'].title }}</div>
      <template v-if="plugins_new['balance-reward'].button.length > 0">
        <div class="gird-3">
          <div @click="selectPlugBtn('balance-reward',item.plugin_code)" class="border flex-column border-radius-6" :class="{'active': plugin_code['balance-reward'] == item.plugin_code }"
          v-for="(item, index) in plugins_new['balance-reward'].button" :key="index">
            <div class="f-14 padding-4 themeColor" style="flex:1;">{{ item.title }}</div>
            <div class="f-11 padding-4 bg-d6d6dc bg-themeColor color-fff">{{ item.content }}</div>
          </div>
        </div>
      </template>
    </div>

    <div class="b-r-12 bg-white p-12 m-12" v-if="sign_info.contract_name">
      <div class="f-bold f-15 t-l" style="line-height: 28px;">合同信息</div>
      <template v-if="!sign_info.contract_id">
        <div class="f-13 c-999999 t-l">根据平台要求，您需完成以下合同签署后再充值{{ balanceLang }}！</div>
        <div class="f-bold f-16" style="line-height: 44px;">《{{sign_info.contract_name}}》</div>
        <van-button type="primary" round style="width: 125px;" size="small" @click="toSignV2">去签署</van-button>
      </template>
      <div v-else class="f-14 t-l">您已于 {{sign_info.signed_time}} 成功签署<em class="f-bold" style="color: #198BFB;" @click.stop="toSignDetail">《{{sign_info.contract_name}}》</em> ，点击合同名称可查阅！</div>
    </div>

    <div class="b-r-12 bg-white p-12 m-12" v-if="bottom_content">
      <div v-html="bottom_content"></div>
    </div>

    <div class="recharge_way" v-if="recharge == 1">
      <div class="title">
        <div class="line"></div>
        <h1>充值方式</h1>
      </div>
      <ul class="choose_box">
        <li @click="confirm_post(btn.value, btn)" v-for="(btn, i) in buttons" :key="i">
          <template v-if="btn.icon">
            <i class="iconfont" :class="btn.icon && btn.icon.icon_url" v-if="btn.icon.icon_url"></i>
            <img class="icon_img" :src="btn.icon && btn.icon.icon_img" width="28px" v-else-if="btn.icon.icon_img"/>
          </template>
          <i class="iconfont icon-pay_default" v-else></i>
          {{ btn.name }}{{ typename }}
          <img class="icon_img" :src="btn.icon && btn.icon.unionpay" width="28px" v-if="btn.icon && btn.icon.unionpay" style="height: 1.5rem;margin-left: 0.5rem;"/>
        </li>
      </ul>
    </div>
    <div style="height: 5rem;"></div>
    <pay-keyboard :payKeyboardShow.sync="popupSpecs" @complete="onInput" @close="changePopupSpecs"></pay-keyboard>
    <newCouponList @childSelectCoupon="childSelectCoupon" @close="couponShowPopup = false" v-model="couponShowPopup" :coupons_new="member_coupon_list"></newCouponList>
    <!-- 快递地址选择器 -->
    <yz-address-list
      ref="yz_showAddressShop"
      :goodsStyle="false"
      v-model="showAddress"
      :center_path="locations"
      :path_list="delivery_area"
      v-on:confirm="confirmSelectAddress"
      :options="yzAddressListOptions"
    ></yz-address-list>
    <van-popup v-model="show" position="bottom" round :close-on-click-overlay="false" :style="{ height: '75vh' }">
      <van-nav-bar title="选择门店" :border="false">
        <template #right>
          <van-icon name="cross" color="#000" @click="showClose" />
        </template>
      </van-nav-bar>
      <van-search v-model="storeNameKey" placeholder="搜索门店" shape="round" show-action>
        <template #action>
          <div @click="getStoreList">搜索</div>
        </template>
      </van-search>
      <div class="storeList">
        <div class="lis" :class="{ selectLis: store_id == item.id }" @click="tapStoreID(item)" v-for="(item, index) in stroeList" :key="index">
          <div class="lisTop">
            <div class="tag" v-if="index == 0">距离最近</div>
            <div class="memberimg">
              <img :src="item.thumb" alt="" />
            </div>
            <div class="storeName">{{ item.store_name }}</div>
          </div>
          <div class="lis_b">
            <i class="iconfont icon-dizhi1"></i>
            <div class="loc">{{ item.distance.toFixed(2) }}{{ item.unit }}</div>
          </div>
          <div class="br_record" v-if="store_id == item.id">
            <i class="iconfont icon-record_go"></i>
          </div>
        </div>
        <div class="moreTxt" @click="getMoreData" v-if="page < total_page">加载更多</div>
      </div>
    </van-popup>
  </div>
</template>
<script>
import member_balance_recharge from "./member_balance_rechargecontroller";
export default member_balance_recharge;
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" rel="stylesheet/scss" scoped>
.moreTxt{
  margin: 0.625rem 0;
  text-align: center;
  color: #999;
}
.storeList {
  padding: 0.84rem 0.75rem;
  box-sizing: border-box;
  background: #fff;
  height: 60vh;
  overflow-y: scroll;
  .lis {
    padding: 0.94rem 0.75rem;
    box-sizing: border-box;
    border-radius: 0.5rem;
    border: 0.03rem solid #d6d6dc;
    margin-bottom: 0.63rem;
    .lis_b {
      display: flex;
      align-items: center;
      color: #6e6e79;
      margin-top: 0.59rem;
      .icon-dizhi1 {
        font-size: 0.75rem;
        margin-right: 0.2rem;
      }
      .loc {
        font-size: 0.75rem;
      }
    }
    .lisTop {
      display: flex;
      align-items: center;
      .tag {
        font-size: 0.75rem;
        color: #f15353;
        padding: 0.16rem 0.25rem;
        border: 0.03rem solid #f15353;
        background: #ffffff;
        border-radius: 0.25rem;
        line-height: 0.9rem;
        margin-right: 0.31rem;
      }
      .memberimg {
        width: 1.25rem;
        height: 1.25rem;
        background: #d6d6dc;
        border-radius: 50%;
        margin-right: 0.25rem;
        flex-shrink: 0;
        img {
          width: 100%;
          height: 100%;
          border-radius: 50%;
        }
      }
      .storeName {
        text-align: left;
        flex: 1;
        font-size: 1rem;
        color: #00001c;
        font-weight: 500;
      }
    }
  }
  .selectLis {
    border: 0.03rem solid #f15353;
    position: relative;
  }
  .br_record {
    position: absolute;
    bottom: 0;
    right: 0;
    .icon-record_go {
      color: #f15353;
    }
  }
}
.b-r-12 {
  border-radius: 0.75rem;
}
.bg-white {
  background-color: #ffffff;
}
.p-12 {
  padding: 0.75rem;
}
.m-12 {
  margin: 0.75rem;
}
.mb-8 {
  margin-bottom: 0.5rem;
}
.mt-8 {
  margin-top: 0.5rem;
}
.c-999999 {
  color: #999999;
}

#balance_recharge {
  .recharge_way {
    background: #fff;
    margin: 0.625rem 0.625rem 0;
    border-radius: 0.75rem;

    .title {
      display: flex;
      align-items: center;
      padding-left: 1rem;

      .line {
        width: 0.125rem;
        height: 0.875rem;
        background: var(--themeBaseColor);
      }

      h1 {
        color: var(--themeBaseColor);
        line-height: 2.5rem;
        text-align: left;
        font-size: 0.9375rem;
        font-weight: 400;
        margin-left: 0.625rem;
      }
    }

    li {
      position: relative;
      display: flex;
      align-items: center;
      line-height: 3.5rem;
      font-size: 16px;
      // margin-left: 1.25rem;
      // padding-right: 1.25rem;
      border-bottom: solid 0.0625rem #ebebeb;
      margin: 0 0.625rem;

      .iconfont_bg {
        background: #f15353;
        width: 2.25rem;
        height: 1.5rem;
        border-radius: 0.1875rem;
        display: flex;
        align-items: center;
        margin-right: 0.625rem;
      }

      .icon-balance_d {
        color: #00908c;
      }

      .icon-balance_e {
        color: #64b42e;
      }

      .icon-balance_f {
        color: #fac337;
      }

      .icon-balance_g {
        color: #00508e;
      }

      .icon-balance_h {
        color: #fac337;
      }

      .icon-balance_i {
        color: #64b42e;
      }

      .icon-balance_j,.icon-pay_default {
        color: #069ce7;
      }

      .icon-balance_z {
        background-image: url(../../../assets/images/pay_e.png);
      }

      .iconfont {
        font-size: 2rem;
        margin-right: 0.625rem;
      }
    }

    li:last-child {
      border: none;
    }
  }

  .main {
    margin: 0 0.625rem;
    // margin-top: -11rem;
    background: #fff;
    border-radius: 0.625rem;
    padding: 1rem 0.75rem 0.75rem 0.75rem;

    .activityBox {
      text-align: left;
      color: #666;

      .txt {
        margin-bottom: 0.5rem;
        color: #000;
      }

      .activityTime {
        margin-bottom: 0.5rem;
      }
    }

    .activityItem {
      display: grid;
      grid-template-columns: 1fr 1fr 1fr;
      grid-row-gap: 10px;
      grid-column-gap: 10px;

      .acitem {
        font-size: 0.625rem;
        padding: 0.75rem 0;
        border-radius: 12px 12px 12px 12px;
        border: 1px solid #D6D6DC;
        display: flex;
        flex-direction: column;
        justify-content: center;
        .right {
          color: #999999;
        }
        input {
          border: none;
          width: 100%;
          padding: 0 0.5rem;
          text-align: center;
        }
      }
      .activeAcitemStyle {
        border-color: #F15353;
        background: #FEEDED;
        color: #F15353;
      }
    }

    .myBalance {
      text-align: left;
    }

    .sum {
      margin: 1rem 0;
      display: flex;
      line-height: 3rem;
      align-items: center;
      border: 1px solid #D6D6DC;
      border-radius: 10px 10px 10px 10px;
      padding: 0 0.75rem;

      input {
        margin-left: 0.75rem;
        border: none;
        font-size: 1.125rem !important;
      }
    }
  }

  .content {
    padding-bottom: 5rem;

    .transfer_info {
      background: #fff;
      padding-left: 0.875rem;
      font-size: 16px;

      .info_a,
      .info_b {
        line-height: 2.875rem;
        border-bottom: solid 0.0625rem #ebebeb;
        display: flex;
        justify-content: flex-start;

        span:first-child {
          width: 6.875rem;
          display: block;
          text-align: left;
        }

        input {
          border: none;
          width: 15.625rem;
        }
      }
    }

    .transfer_sum {
      background: #fff;
      padding: 0.625rem 0.875rem;

      span {
        display: block;
        font-size: 16px;
        line-height: 2.5rem;
        text-align: left;
      }

      .sum {
        text-align: left;
        font-size: 24px;

        input {
          margin-left: 0.375rem;
          line-height: 3.75rem;
          width: 90%;
          font-size: 36px;
          border: none;
        }
      }
    }

    .activity_des {
      background: #fff;
      padding: 0.625rem 0.875rem;
      margin-top: 0.625rem;
      text-align: left;

      .title {
        display: block;
        font-size: 16px;
        font-weight: 600;
        margin-bottom: 1rem;
      }

      li {
        position: relative;
        margin: 0.6rem 0.2rem 0.6rem 1rem;

        span {
          font-size: 12px;
        }
      }

      .activity-item::after {
        position: absolute;
        content: "";
        top: 50%;
        left: -0.5rem;
        transform: translateY(-50%);
        width: 2px;
        height: 2px;
        border-radius: 50%;
        background: black;
      }
    }

    .bottom_btn {
      width: 100%;
      background: #fff;
      padding: 0.625rem 0;
      position: fixed;
      bottom: 0;
      border-top: solid 0.0625rem #ebebeb;

      .btn {
        width: 21.5625rem;
        margin: 0 auto;
        height: 2.875rem;
        border-radius: 0.25rem;
        font-size: 16px;
        color: #fff;
        background: #f15353;
        border: none;
      }
    }
  }

  .my_wrapper {
    background: #fff;
    overflow: hidden;
    display: flex;
    padding: 0 14px;
    line-height: 3.0625rem;
    height: 3.0625rem;

    span {
      text-align: left;
      font-size: 16px;
      line-height: 3.0625rem;
    }

    .my-value {
      flex: 2;
      text-align: left;

      span {
        color: #f15353;
      }
    }
  }
}

.mint-field .mint-cell-title {
  width: 5rem;
  -webkit-box-flex: 0;
  -ms-flex: none;
  flex: none;
  text-align: left;
  margin-left: 0.9375rem;
}

.icon-pay_yue {
  color: #ff7433;
}
.icon-guizhouyinhangjuhezhifu {
  color: #ff3333;
}

.icon-pay_wechat {
  color: #ff7433;
}

.icon-pay_alipay {
  color: #29a1f7;
}

.icon-pay_quick {
  color: #46e0d1;
}
.tips {
  text-align: left;
  margin-top: 1rem;
}

.addressCell {
  margin: 0 0.625rem;
  margin-top: -10rem;
  margin-bottom: 0.63rem;
  height: 3.13rem;
  background: #ffffff;
  border-radius: 0.63rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.75rem;
  box-sizing: border-box;
  .addressCell_l {
    align-items: center;
    flex: 1;
    overflow: hidden;
    .txt {
      margin-left: 0.28rem;
      overflow: hidden;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }
  .addressCell_r {
    align-items: center;
    flex-shrink: 0;
  }
}
.cellOther {
  margin: 0.63rem 0.625rem;
  padding: 0 0.75rem;
  box-sizing: border-box;
  height: 3rem;
  background: #ffffff;
  border-radius: 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.81rem;
  .cellOther_r {
    color: #f15353;
    .icon-icon_more11 {
      color: #aaaab3;
    }
  }
}
.activity_box {
  .txt {
    font-weight: 500;
    font-size: 0.88rem;
    color: #00001c;
    margin-top: 1.06rem;
    text-align: left;
  }
  .activity_lis {
    margin-top: 0.75rem;
    .activity_time {
      text-align: left;
      margin-bottom: 0.91rem;
      font-size: 0.79rem;
      color: #aaaab3;
    }
    .activity_item {
      text-align: left;
      margin-bottom: 0.63rem;
      font-size: 0.79rem;
      color: #00001c;
    }
    .activity_item:last-child {
      margin-bottom: 0;
    }
  }
}
.gird-3{
  display: grid;
  grid-template-columns: repeat(3,1fr);
  grid-gap: 10px;
  margin-top: 10px;
}
.border{
  border: 1px solid #ebebeb;
}
.padding-4{
  padding: 4px;
}
.color-fff{
  color: #fff;
}
.bg-d6d6dc{
  background: #d6d6dc;
}
.active {
  .bg-themeColor{
    background: var(--themeBaseColor);
  }
  .themeColor{
    color: var(--themeBaseColor);
  }
}

.border-radius-6 {
  border-radius: 6px;
  overflow: hidden;
}
.icon_img{
  width: 1.75rem;
  height: 1.75rem;
  margin: 0 0.75rem 0 0;
  display: block;
  object-fit: contain;
}
</style>
